---
swagger: '2.0'
info:
  version: 1.0.0
  title: GeoServer XSLT transforms
  description: A transform contains a style sheet that can be used to generate a new textual output format of user choosing for WFS
  contact:
    name: GeoServer
    email: 'geoserver-users@sourceforge.net'
    url: 'http://geoserver.org/comm/'
host: localhost:8080
basePath: /geoserver/rest

paths:

  /services/wfs/transforms:

    get:
      operationId: getTransforms
      tags:
       - "Transforms"
      summary: List available transformations.
      description: Displays a list of all the transforms information available on the server. Use the "Accept:" header to specify format or append an extension to the endpoint (example "/styles.xml" for XML).
      produces:
        - application/xml
        - application/json
        - text/html
      responses:
        200:
          description: OK
          schema:
            $ref: "#/definitions/TransformList"
          examples:
            application/xml: |
              <transforms>
                <transform>
                  <name>test</name>
                  <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/restng/services/wfs/transforms/test.xml" type="application/atom+xml"/>
                </transform>
                <transform>
                  <name>test1</name>
                  <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/restng/services/wfs/transforms/test1.xml" type="application/atom+xml"/>
                </transform>
              </transforms>
            
            application/json: |
              {
                "transforms": {
                  "transform": [
                    {
                      "name": "test",
                      "href": "http://localhost:8080/geoserver/restng/services/wfs/transforms/test.json"
                    },
                    {
                      "name": "test1",
                      "href": "http://localhost:8080/geoserver/restng/services/wfs/transforms/test1.json"
                    }
                  ]
                }
              }

    post:
      operationId: postTransform
      tags:
       - "Transforms"
      summary: Add a new transform
      description: Adds a new transform to the server. If the content type used is application/xml the server will assume a <transform> definition is being posted, and the XSLT will have to be uploaded separately using a PUT request with content type application/xslt+xml against the transformation resource. If the content type used is application/xslt+xml the server will assume the XSLT itself is being posted, and the name, sourceFormat, outputFormat, outputMimeType query parameters will be used to fill in the transform configuration instead.
      parameters:
        - name: transformBody
          description: Transform body to upload.
          in: body
          required: true
          schema:
            $ref: "#/definitions/Transform"
        - name: name
          in: query
          required: false
          description: Name of the transformation.
          type: string
        - name: sourceFormat
          in: query
          required: false
          description: Source format of the transformation.
          type: string
        - name: outputFormat
          in: query
          required: false
          description: Output format of the transformation.
          type: string
        - name: outputMimeType
          in: query
          required: false
          description: Output mime type of the transformation.
          type: string
        - name: fileExtension
          in: query
          required: false
          description: The extension of the file generated by the transformation.
          type: string
      consumes:
        - application/xml
        - application/xslt+xml
        - application/json
        - text/html
      responses:
        201:
          description: Created

    put:
      operationId: putTransform
      tags:
       - "Transforms"
      description: Invalid. Use POST for adding a new transformation.
      responses:
        405:
          description: Method Not Allowed

    delete:
      operationId: deleteTransform
      tags:
       - "Transforms"
      description: Invalid.
      responses:
        405:
          description: Method Not Allowed


  /services/wfs/transforms/{transform}:

    get:
      operationId: getTransform
      tags:
       - "Transforms"
      summary: Retrieve a transformation.
      description: Retrieves a single transformation.
      produces:
        - application/xml
        - application/xslt+xml
        - application/json
        - text/html
      parameters:
        - name: transform
          in: path
          required: true
          description: Name of the transformation.
          type: string
      responses:
        200:
          description: OK
          schema:
            $ref: "#/definitions/Transform"
          examples:
            application/xml: |
              <transform>
                <name>test1</name>
                <sourceFormat>text/xml; subtype=gml/2.1.2</sourceFormat>
                <outputFormat>text/html</outputFormat>
                <xslt>test1.xslt</xslt>
              </transform>
            
            application/json: |
              {
                "transform": {
                  "name": "test1",
                  "sourceFormat": "text/xml; subtype=gml/2.1.2",
                  "outputFormat": "text/html",
                  "xslt": "test1.xslt"
                }
              }

            application/xslt+xml: |
              <?xml version="1.0" encoding="ISO-8859-1"?>
              <xsl:stylesheet version="1.0" xmlns:wfs="http://www.opengis.net/wfs"
                xmlns:tiger="http://www.census.gov" xmlns:gml="http://www.opengis.net/gml"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                <xsl:template match="/">
                  <html>
                    <body>
                    <xsl:for-each select="wfs:FeatureCollection/gml:featureMember/*">
                      <h2><xsl:value-of select="@fid"/></h2>
                      <table border="1">
                        <tr>
                          <th>Attribute</th>
                          <th>Value</th>
                        </tr>
                          <!-- [not(*)] strips away all nodes having
                               children, in particular, geometries -->
                          <xsl:for-each select="./*[not(*)]">
                          <tr>
                            <td>
                              <xsl:value-of select="name()" />
                            </td>
                            <td>
                              <xsl:value-of select="." />
                            </td>
                          </tr>
                          </xsl:for-each>
                      </table>
                   </xsl:for-each>
                   </body>
                 </html>
                </xsl:template>
              </xsl:stylesheet>
                        

    post:
      operationId: postTranform
      tags:
       - "Transforms"
      description: Invalid.
      responses:
        405:
          description: Method Not Allowed

    put:
      operationId: putTranform
      tags:
       - "Transforms"
      summary: Modify a single transform
      description: Modifies a single transform.
      parameters:
        - name: transformBody
          description: Transform body to upload.
          in: body
          required: true
          schema:
            $ref: "#/definitions/Transform"
        - name: transform
          in: path
          required: true
          description: Name of the transformation.
          type: string
      consumes:
        - application/xml
        - application/json
        - application/xslt+xml
      responses:
        200:
          description: OK
        401:
          description: Unauthorized

    delete:
      operationId: deleteTranform
      tags:
       - "Transforms"
      summary: Delete transformation
      description: Deletes a transformation.
      parameters:
        - name: transform
          in: path
          required: true
          description: Name of the transformation.
          type: string
      responses:
        200:
          description: OK
        401:
          description: Unauthorized

definitions:

  TransformList:
    title: transforms
    type: array
    items:
      $ref: '#/definitions/TransformListItem'

  TransformListItem:
    title: transform
    type: object
    properties:
      name:
        type: string
        description: Name of the transformation
      href:
        type: string
        description: URL to the transformation

  Transform:
    title: transform
    xml:
      name: transform
    type: object
    properties:
      name:
        type: string
        description: Name of the transformation
      sourceFormat:
        type: string
        description: Source format accepted by the transformation
      outputFormat:
        type: string
        description: Output format produced by the transformation
      xslt:
        type: string
        description: Style sheet associated with the transformation